﻿using Hxj.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace  Utility.Json
{
    public struct JsonJqGridData<TEntity> where TEntity : Entity
    {
        /// <summary>
        /// 当前页
        /// </summary>
        public int page;
        /// <summary>
        /// 总记录数
        /// </summary>
        public int total;
        /// <summary>
        /// 记录数
        /// </summary>
        public int records;
        /// <summary>
        /// List数据行
        /// </summary>
        public List<TEntity> rows;
        /// <summary>
        /// 解析成Json数据
        /// </summary>
        /// <returns></returns>
        public string ToJsonString()
        {
            string strRows = JsonHelper.JsonSerializerDate(this);
            if (rows != null)
            {
                rows = null;
            }
            return strRows;
        }
        /// <summary>
        /// 重写,解析成Json数据
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return ToJsonString();
        }
    }
    
    /// <summary>
    /// Grid列表返回Json数据
    /// </summary>
    public struct JsonJqGridData
    {
        /// <summary>
        /// 当前页
        /// </summary>
        public int page;
        /// <summary>
        /// 总记录数
        /// </summary>
        public int total;
        /// <summary>
        /// 记录数
        /// </summary>
        public int records;
        /// <summary>
        /// Table数据行
        /// </summary>
        public DataTable rows;
        /// <summary>
        /// 解析成Json数据
        /// </summary>
        /// <returns></returns>
        public string ToJsonString()
        {
            string strJson = string.Concat("{", "\"page\":" + page + "", ",\"total\":" + total + "", ",\"records\":" + records + "", ",\"rows\":" + JsonHelper.Serialize(rows) + "", "}");
            if (rows != null)
            {
                rows.Dispose();
                rows = null;
            }
            return strJson;
        }
        /// <summary>
        /// 重写,解析成Json数据
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return ToJsonString();
        }
    }
}
